package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.Tools.CodeMsg;
import com.stylefeng.guns.core.common.Tools.Result;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.core.validater.Insert;
import com.stylefeng.guns.core.validater.Update;
import com.stylefeng.guns.modular.system.model.SysSerialnumInf;
import com.stylefeng.guns.modular.system.service.ISysSerialnumInfService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.stylefeng.guns.core.common.annotion.BussinessLog;

import java.util.HashMap;
import java.util.Map;

/**
 * 系统流水号信息
 *
 * @author sasazaixian
 * @Date 2018-10-25 18:29
 */
@Controller
@RequestMapping(value = {"/gunsApi/auth/sysSerialnumInf"})
@Api(value = "系统流水号信息操作相关api", tags = {"系统流水号信息操作接口"})
public class SysSerialnumInfController extends BaseController {
    @Autowired
    private ISysSerialnumInfService sysSerialnumInfService;
	
    /**
     * 分页获取系统流水号信息列表
     * @param sysSerialnumInf
     * @param pageNum
     * @param pageSize
     * @return	
     */
    @ApiOperation(value = "分页获取系统流水号信息列表", notes = "分页获取系统流水号信息列表", httpMethod = "POST")
    @PostMapping(value = "/pageList", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)	
    @ResponseBody
    public Result pageList(
        @RequestBody @ApiParam(name = "sysSerialnumInf", value = "系统流水号信息对象")SysSerialnumInf sysSerialnumInf,
        @ApiParam(name = "pageNum", value = "当前页数", required = true) @RequestParam(value = "pageNum", required = true) Integer pageNum,
        @ApiParam(name = "pageSize", value = "每页显示条数", required = true) @RequestParam(value = "pageSize", required = true) Integer pageSize		
        ) {
        try {
            Pager pager=new Pager();
            pager.setPageNumber(pageNum);//页码从1 开始
            pager.setPageSize(pageSize);
            pager.setObj(sysSerialnumInf);			
            return Result.success( sysSerialnumInfService.pageListSysSerialnumInf(pager,getToken()));
        }catch(Exception e){
            return Result.error(CodeMsg.SERVER_EXCEPTION,e.getMessage());
        }
    }
    /**
     * 获取系统流水号信息列表
     * @param sysSerialnumInf    
     * @return	
     */
    @ApiOperation(value = "获取系统流水号信息列表", notes = "获取系统流水号信息列表", httpMethod = "POST")
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)	
    @ResponseBody
    public Result list(
        @RequestBody @ApiParam(name = "sysSerialnumInf", value = "系统流水号信息对象")SysSerialnumInf sysSerialnumInf) {
        try {            
            return Result.success( sysSerialnumInfService.selectListSysSerialnumInf(sysSerialnumInf,getToken()));
        }catch(Exception e){
            return Result.error(CodeMsg.SERVER_EXCEPTION,e.getMessage());
        }
    }
    /**
     * 通过主键获取系统流水号信息对象
     * @param ssiType
     * @return
     */
    @ApiOperation(value = "获取流水号", notes = "获取流水号", httpMethod = "GET")
    @GetMapping(value = "/getById", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public Result getSerialnum(
            @ApiParam(name = "ssiType", value = "流水类型", required = true) @RequestParam(value = "ssiType", required = true) String  ssiType,
            @ApiParam(name = "dateFormatStr", value = "日期格式 例如yyyy-MM-dd ", required = true) @RequestParam(value = "dateFormatStr", required = true) String dateFormatStr,
            @ApiParam(name = "len", value = "流水长度", required = true) @RequestParam(value = "len", required = true) Integer len

    ) {
        try {
            Map map=new HashMap<String,String>();
            map.put("newNo",sysSerialnumInfService.updateSysSerialnumInf(ssiType,dateFormatStr,len,getToken()));
            return Result.success(map);
        }catch(Exception e){
            return Result.error(CodeMsg.SERVER_EXCEPTION,e.getMessage());
        }
    }


	private String getToken(){		
		return getHttpServletRequest().getHeader("Authorization").substring(7);
    }
}
